/**
 * 只要包含列出的任意一个权限，元素就会显示
 */
import React, { Component } from 'react';
import PropTypes from 'prop-types'
import db from '@/utils/localstorage';

export  let HasAnyPermission = ComposedComponent =>class WrapComponent extends Component {
    constructor(props) {
      super(props);
    }
  
    // static propTypes = {
    //   auth:PropTypes.string.isRequired,
    // };
    hasAnyPermission=()=>{
      let permissions = db.get('permissions');
      if(!permissions||Object.keys(permissions).length==0){
        permissions=[]
      }
      const value = this.props.auth;
      let flag = true
      for (const v of value) {
        if (permissions.includes(v)) {
          flag = true
        }
      }
     return flag
    }
    render() {
      //如果权限有值，并且具备权限，那么创建按钮
      return this.hasAnyPermission()?<ComposedComponent { ...this.props} />:null;
    }
  };